package com.njtoyo.taxi.admin.rest.controller.business.operation_rule;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.njtoyo.taxi.admin.mapper.master.entity.OnlineValuationRule;
import com.njtoyo.taxi.admin.rest.pojo.dto.rule.TimeIntervalDTO;
import com.njtoyo.taxi.admin.rest.wrapper.business.operation_rule.online_valuation.OnlineValuationAddUpdateWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.business.operation_rule.online_valuation.OnlineValuationMockPricingWrapper;
import com.njtoyo.taxi.admin.service.business.operation_rule.OnlineValuationRuleService;
import com.njtoyo.taxi.entity.backend.AdminUser;
import com.taxi.entity.common.RestResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.math.BigDecimal;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

@RestController
@Api(value = "线上计价规则", tags = "线上计价规则")
@RequestMapping("business/operation-rule/online-valuation")
public class OnlineValuationRuleController {

    @Autowired
    OnlineValuationRuleService onlineValuationRuleService;


    @RequestMapping("/page")
    public RestResult page(@RequestParam(value = "current", required = false, defaultValue = "1") Integer current,
                           @RequestParam(value = "size", required = false, defaultValue = "15") Integer size,
                           @RequestParam(value = "driverRegionId", required = false) String driverRegionId,
                           @RequestParam(value = "isActive", required = false) Boolean isActive) {
        return onlineValuationRuleService.page(current, size, driverRegionId, isActive);
    }


    @PostMapping("/add")
    public RestResult add(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser, @RequestBody OnlineValuationAddUpdateWrapper wrapper) {
        RestResult result = checkParams(wrapper);
        if (!result.isSuccess()) {
            return result;
        }
        RestResult driverRegionResult = checkDriverRegionIsActive(wrapper.getId(), wrapper.getDriverRegionId(), wrapper.getIsActive());
        if (!driverRegionResult.isSuccess()) {
            return driverRegionResult;
        }
        return onlineValuationRuleService.add(wrapper, adminUser);
    }

    private RestResult checkDriverRegionIsActive(Long driverRegionId, Long ruleId, Boolean isActive) {
        if (isActive) {
            List<OnlineValuationRule> list = onlineValuationRuleService.selectByDriverRegionIdOpen(ruleId, driverRegionId);
            if (CollUtil.isNotEmpty(list)) {
                return RestResult.failed("该司机区域下已有开启的规则，请先关闭");
            }
        }
        return RestResult.success();
    }

    @PostMapping("/update")
    public RestResult update(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser, @RequestBody OnlineValuationAddUpdateWrapper wrapper) {
        RestResult result = checkParams(wrapper);
        if (!result.isSuccess()) {
            return result;
        }
        RestResult driverRegionResult = checkDriverRegionIsActive(wrapper.getId(), wrapper.getDriverRegionId(), wrapper.getIsActive());
        if (!driverRegionResult.isSuccess()) {
            return driverRegionResult;
        }
        return onlineValuationRuleService.update(wrapper, adminUser);
    }


    @GetMapping("/detail/{id}")
    public RestResult detail(@PathVariable("id") String id) {
        return onlineValuationRuleService.getDetailById(id);
    }


    @GetMapping("/checkDriverRegionIsActive/{driverRegionId}")
    public RestResult checkDriverRegionIsActive(@PathVariable("driverRegionId") String driverRegionId) {
        return onlineValuationRuleService.checkDriverRegionIsActive(driverRegionId);
    }

    @PostMapping("/switchIsActive")
    public RestResult switchIsActive(@RequestBody OnlineValuationRule rule) {
        OnlineValuationRule onlineValuationRule = onlineValuationRuleService.selectOneById(rule.getId());
        if (ObjectUtil.isNull(onlineValuationRule)) {
            return RestResult.failed("操作失败,该规则不存在");
        }
//        RestResult driverRegionResult = checkDriverRegionIsActive(onlineValuationRule.getId(), onlineValuationRule.getDriverRegionId(), rule.getIsActive());
//        if (!driverRegionResult.isSuccess()) {
//            return driverRegionResult;
//        }
        return onlineValuationRuleService.switchIsActive(rule);
    }

    @PostMapping("/switchCanEditPrice")
    public RestResult switchCanEditPrice(@RequestBody OnlineValuationRule rule) {
        OnlineValuationRule onlineValuationRule = onlineValuationRuleService.selectOneById(rule.getId());
        if (ObjectUtil.isNull(onlineValuationRule)) {
            return RestResult.failed("操作失败,该规则不存在");
        }
        return onlineValuationRuleService.switchCanEditPrice(rule);
    }

    private RestResult checkParams(OnlineValuationAddUpdateWrapper wrapper) {
        if (wrapper.getDriverRegionId() == null) {
            return RestResult.failed("司机区域不能为空");
        }
        if (wrapper.getIsActive() == null) {
            return RestResult.failed("请选择是否开启");
        }
        if (StrUtil.isBlank(wrapper.getStartPriceKM()) || StrUtil.isBlank(wrapper.getStartPriceMinute())) {
            return RestResult.failed("请填写起步价范围");
        }
        if (StrUtil.isBlank(wrapper.getRefreshKM()) || StrUtil.isBlank(wrapper.getRefreshTime())) {
            return RestResult.failed("请填写价格更新间隔");
        }
        RestResult workResult = checkRuleDetailArray(wrapper.getWorkRuleDetails(), false);
        if (!workResult.isSuccess()) {
            return workResult;
        }
        RestResult weekendResult = checkRuleDetailArray(wrapper.getWeekendRuleDetails(), true);
        if (!weekendResult.isSuccess()) {
            return weekendResult;
        }
        return RestResult.success();
    }

    private RestResult checkRuleDetailArray(OnlineValuationAddUpdateWrapper.RuleDetail[] details, Boolean isWeekend) {
        String prefix = isWeekend ? "休息日计费" : "常规计费";
        if (ArrayUtil.isEmpty(details)) {
            return RestResult.failed(StrUtil.format("【{}】规则不能为空", prefix));
        }
        List<OnlineValuationAddUpdateWrapper.RuleDetail> list = Arrays.asList(details);
        Map<String, List<OnlineValuationAddUpdateWrapper.RuleDetail>> titleGroups = list.stream()
                .collect(Collectors.groupingBy(OnlineValuationAddUpdateWrapper.RuleDetail::getTitle));
        Map<String, List<OnlineValuationAddUpdateWrapper.RuleDetail>> duplicateGroups = titleGroups.entrySet().stream()
                .filter(entry -> entry.getValue().size() > 1)
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        List<String> duplicateNames = duplicateGroups.keySet().stream().collect(Collectors.toList());

        List<TimeIntervalDTO> timeRangeList = new ArrayList<>();
        for (int i = 0; i < details.length; i++) {
            OnlineValuationAddUpdateWrapper.RuleDetail ruleDetail = details[i];
            if (StrUtil.isBlank(ruleDetail.getTitle())) {
                return RestResult.failed(StrUtil.format("【{}】的规则名称{}标题不能为空", prefix, i + 1));
            } else if (ruleDetail.getTitle().length() > 15) {
                return RestResult.failed(StrUtil.format("【{}】的规则名称{}标题长度不能超过15个字符", prefix, i + 1));
            }
            if (CollUtil.isNotEmpty(duplicateNames)) {
                String result = StrUtil.format("【{}】的规则名称【{}】存在重名", prefix, duplicateNames.get(0));
                return RestResult.failed(result);
            }
            if (ArrayUtil.isEmpty(ruleDetail.getTimeRanges())) {
                return RestResult.failed(StrUtil.format("【{}】的规则名称【{}】时间范围不能为空", prefix, i + 1));
            }
            for (int j = 0; j < ruleDetail.getTimeRanges().length; j++) {
                TimeIntervalDTO dto = new TimeIntervalDTO();
                Date startDate = null;
                Date endDate = null;
                if (StrUtil.isBlank(ruleDetail.getTimeRanges()[j].getStartTime())) {
                    return RestResult.failed(StrUtil.format("【{}】规则名称【{}】的【时段{}】开始时间不能为空", prefix, ruleDetail.getTitle(), j + 1));
                } else if (StrUtil.isBlank(ruleDetail.getTimeRanges()[j].getEndTime())) {
                    return RestResult.failed(StrUtil.format("【{}】规则名称【{}】的【时段{}】结束时间不能为空", prefix, ruleDetail.getTitle(), j + 1));
                }
                if (ruleDetail.getTimeRanges()[j].getStartTime().contains("T")) {
                    startDate = DateUtil.parseUTC(ruleDetail.getTimeRanges()[j].getStartTime())
                            .setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
                } else {
                    startDate = DateUtil.parse(ruleDetail.getTimeRanges()[j].getStartTime());
                }
                if (ruleDetail.getTimeRanges()[j].getEndTime().contains("T")) {
                    endDate = DateUtil.parseUTC(ruleDetail.getTimeRanges()[j].getEndTime())
                            .setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
                } else {
                    endDate = DateUtil.parse(ruleDetail.getTimeRanges()[j].getEndTime());
                }
                if (startDate.getTime() > endDate.getTime()) {
                    return RestResult.failed(StrUtil.format("【{}】规则名称【{}】的【时段{}】开始时间不能大于结束时间", prefix, ruleDetail.getTitle(), j + 1));
                }
                dto.setTitle(ruleDetail.getTitle());
                dto.setIndex(ruleDetail.getTimeRanges()[j].getIndex());
                dto.setStartTime(LocalTime.parse(DateUtil.format(startDate, "HH:mm")));
                dto.setEndTime(LocalTime.parse(DateUtil.format(endDate, "HH:mm")));
                timeRangeList.add(dto);
            }
            //校验起步价
            if (StrUtil.isBlank(ruleDetail.getStartPrice())) {
                return RestResult.failed(StrUtil.format("【{}】规则名称【{}】的【起步价】不能为空", prefix, ruleDetail.getTitle()));
            }
            //校验超出费
            if (StrUtil.isBlank(ruleDetail.getTimeUnitPrice()) || StrUtil.isBlank(ruleDetail.getMileageUnitPrice())) {
                return RestResult.failed(StrUtil.format("【{}】规则名称【{}】的【超出里程费】或【超出时长费】未设置完整", prefix, ruleDetail.getTitle()));
            }
            //校验等待时长
            if (ruleDetail.getFlag().getWaiting() && (StrUtil.isBlank(ruleDetail.getWaiting().getFreeTime()) ||
                    StrUtil.isBlank(ruleDetail.getWaiting().getTimeCost()) || StrUtil.isBlank(ruleDetail.getWaiting().getLimit()))) {
                return RestResult.failed(StrUtil.format("请完善【{}】规则名称【{}】的【司机等待时长】设置", prefix, ruleDetail.getTitle()));
            }
            //校验调度费设置
            if (ruleDetail.getFlag().getPriceMarkup() && (StrUtil.isBlank(ruleDetail.getPriceMarkup().getRangeStart()) ||
                    StrUtil.isBlank(ruleDetail.getPriceMarkup().getRangeEnd()) || StrUtil.isBlank(ruleDetail.getPriceMarkup().getStep()))) {
                return RestResult.failed(StrUtil.format("请完善【{}】规则名称【{}】的【乘客调度费】设置", prefix, ruleDetail.getTitle()));
            } else if (ruleDetail.getFlag().getPriceMarkup()) {
                int start = Convert.toInt(ruleDetail.getPriceMarkup().getRangeStart());
                int end = Convert.toInt(ruleDetail.getPriceMarkup().getRangeEnd());
                int step = Convert.toInt(ruleDetail.getPriceMarkup().getStep());
                if (start > end) {
                    return RestResult.failed(StrUtil.format("【{}】规则名称【{}】的【乘客调度费】的区间范围设置有误", prefix, ruleDetail.getTitle()));
                }
                if (step > (end - start)) {
                    return RestResult.failed(StrUtil.format("【{}】规则名称【{}】的【乘客调度费】的价格间隔设置有误", prefix, ruleDetail.getTitle()));
                }
            }
            //校验返空费设置
            if (ruleDetail.getFlag().getEmptyBackFee() && (StrUtil.isBlank(ruleDetail.getEmptyBackFee().getRatio()) ||
                    StrUtil.isBlank(ruleDetail.getEmptyBackFee().getBaseMileage()))) {
                return RestResult.failed(StrUtil.format("请完善【{}】规则名称【{}】的【返空费】设置", prefix, ruleDetail.getTitle()));
            } else if (StrUtil.isNotBlank(ruleDetail.getEmptyBackFee().getRatio())) {
                if (Convert.toBigDecimal(ruleDetail.getEmptyBackFee().getRatio()).compareTo(new BigDecimal(100)) > 0) {
                    return RestResult.failed(StrUtil.format("【{}】规则名称【{}】的【返空费】的加收里程费不能大于100%", prefix, ruleDetail.getTitle()));
                }
            }
            //校验恶劣天气设置
            if (ruleDetail.getFlag().getBadWeather() && (StrUtil.isBlank(ruleDetail.getBadWeather().getPrice()) ||
                    StrUtil.isBlank(ruleDetail.getBadWeather().getStartTime()) || StrUtil.isBlank(ruleDetail.getBadWeather().getEndTime()))) {
                return RestResult.failed(StrUtil.format("请完善【{}】规则名称【{}】的【恶劣天气附加费】设置", prefix, ruleDetail.getTitle()));
            }
            if (ruleDetail.getFlag().getBadWeather()) {
                if (StrUtil.isBlank(ruleDetail.getBadWeather().getPrice()) ||
                        StrUtil.isBlank(ruleDetail.getBadWeather().getStartTime()) || StrUtil.isBlank(ruleDetail.getBadWeather().getEndTime())) {
                    return RestResult.failed(StrUtil.format("请完善【{}】规则名称【{}】的【恶劣天气附加费】设置", prefix, ruleDetail.getTitle()));
                } else if (DateUtil.parse(ruleDetail.getBadWeather().getEndTime()).isBefore(DateUtil.date())) {
                    return RestResult.failed(StrUtil.format("【{}】规则名称【{}】的【恶劣天气】日期结束时间不能早于当前时间", prefix, ruleDetail.getTitle()));
                }
            }
            //校验节假日设置  TODO
            if (ruleDetail.getFlag().getHoliday()) {
                if (StrUtil.isBlank(ruleDetail.getHoliday().getPrice())) {
                    return RestResult.failed(StrUtil.format("请完善【{}】规则名称【{}】的【节假日附加费】设置", prefix, ruleDetail.getTitle()));
                }
                for (int j = 0; j < ruleDetail.getHoliday().getDays().length; j++) {
                    OnlineValuationAddUpdateWrapper.RuleDetail.Days day = ruleDetail.getHoliday().getDays()[j];
                    if (StrUtil.isBlank(day.getStartTime()) || StrUtil.isBlank(day.getEndTime())) {
                        return RestResult.failed(StrUtil.format("请完善【{}】规则名称【{}】的【节假日附加费】的【假期{}】时间设置", prefix, ruleDetail.getTitle(), (day.getIndex() + 1)));
                    } else if (DateUtil.parse(day.getEndTime()).isBefore(DateUtil.date())) {
                        return RestResult.failed(StrUtil.format("请完善【{}】规则名称【{}】的【节假日附加费】的【假期{}】日期结束时间不能早于当前时间", prefix, ruleDetail.getTitle(), (day.getIndex() + 1)));
                    }
                }
            }
            //校验司机抽成设置
            if (ruleDetail.getFlag().getDriverCommission() && StrUtil.isBlank(ruleDetail.getDriverCommission().getRatio())) {
                return RestResult.failed(StrUtil.format("请完善【{}】规则名称【{}】的【司机抽成】设置", prefix, ruleDetail.getTitle()));
            } else if (StrUtil.isNotBlank(ruleDetail.getDriverCommission().getRatio())) {
                if (Convert.toBigDecimal(ruleDetail.getDriverCommission().getRatio()).compareTo(new BigDecimal(100)) > 0) {
                    return RestResult.failed(StrUtil.format("【{}】规则名称【{}】的【司机抽成】不能大于100%", prefix, ruleDetail.getTitle()));
                }
                if (ObjectUtil.isNotNull(ruleDetail.getDriverCommission().getMin()) && ObjectUtil.isNotNull(ruleDetail.getDriverCommission().getMax()) &&
                        ruleDetail.getDriverCommission().getMin().compareTo(ruleDetail.getDriverCommission().getMax()) >= 0) {
                    return RestResult.failed(StrUtil.format("【{}】规则名称【{}】的【司机抽成】最小抽成不能大于或等于最大抽成", prefix, ruleDetail.getTitle()));
                }

            }
            //校验乘客信息服务费部分设置
            if (ruleDetail.getFlag().getInfoFee() && StrUtil.isBlank(ruleDetail.getInfoFee().getRatio())) {
                return RestResult.failed(StrUtil.format("请完善【{}】规则名称【{}】的【乘客信息服务费】设置", prefix, ruleDetail.getTitle()));
            } else if (StrUtil.isNotBlank(ruleDetail.getInfoFee().getRatio())) {
                if (Convert.toBigDecimal(ruleDetail.getInfoFee().getRatio()).compareTo(new BigDecimal(100)) > 0) {
                    return RestResult.failed(StrUtil.format("【{}】规则名称【{}】的【乘客信息服务费抽成】不能大于100%", prefix, ruleDetail.getTitle()));
                }

                if (ObjectUtil.isNotNull(ruleDetail.getInfoFee().getMin()) && ObjectUtil.isNotNull(ruleDetail.getInfoFee().getMax())
                        && ruleDetail.getInfoFee().getMin().compareTo(ruleDetail.getInfoFee().getMax()) >= 0) {
                    return RestResult.failed(StrUtil.format("【{}】规则名称【{}】的【乘客信息服务费抽成】最小抽成不能大于或等于最大抽成", prefix, ruleDetail.getTitle()));
                }
            }
        }
        RestResult result = checkTimeIntervals(timeRangeList, prefix);
        if (result != null) {
            return result;
        }
        return RestResult.success();
    }

    private RestResult checkTimeIntervals(List<TimeIntervalDTO> timeIntervals, String prefix) {
        // 创建两个新列表避免修改原始数据
        List<TimeIntervalDTO> sortedByStart = new ArrayList<>(timeIntervals);
        List<TimeIntervalDTO> sortedByEnd = new ArrayList<>(timeIntervals);
        // 按开始时间排序
        Collections.sort(sortedByStart, Comparator.comparing(TimeIntervalDTO::getStartTime));
        // 按结束时间排序
        Collections.sort(sortedByEnd, Comparator.comparing(TimeIntervalDTO::getEndTime));
        // 检查是否从 00:00 开始
        if (timeIntervals.isEmpty() || !sortedByStart.get(0).getStartTime().equals(LocalTime.MIN)) {

            return RestResult.failed(StrUtil.format("【{}】时间范围不是从【00:00】开始", prefix));
        }
        if (timeIntervals.isEmpty() || !sortedByEnd.get(sortedByEnd.size() - 1).getEndTime().format(DateTimeFormatter.ofPattern("HH:mm")).equals("23:59")) {
            return RestResult.failed(StrUtil.format("【{}】时间范围不是从【23:59】结束", prefix));
        }
        //上个时间段参数
        Date lastStartTime = DateUtil.parseDateTime("1970-01-01 00:00:00");
        Date lastEndTime = DateUtil.parseDateTime("1970-01-01 00:00:00");
        Integer lastIndex = 0;
        String lastTitle = "";
        List<TimeIntervalDTO> checkOverTimes = new ArrayList<>();

        for (int i = 0; i < sortedByStart.size(); i++) {
            TimeIntervalDTO interval = sortedByStart.get(i);
            //格式化当前时间段时间
            Date startTime = DateUtil.parseDateTime(StrUtil.format("{} {}:00", "1970-01-01", interval.getStartTime().format(DateTimeFormatter.ofPattern("HH:mm"))));
            Date endTime = DateUtil.parseDateTime(StrUtil.format("{} {}:00", "1970-01-01", interval.getEndTime().format(DateTimeFormatter.ofPattern("HH:mm"))));
            if (StrUtil.isBlank(lastTitle)) {
                lastTitle = interval.getTitle();
            }
            // 检查同一个时段是否大于开始时间
            if (!interval.getEndTime().isAfter(interval.getStartTime())) {
                return RestResult.failed(StrUtil.format("【{}】规则标题【{}】时间大于开始时间", prefix, interval.getTitle()));
            }
            // 检查是否有交集
            String checkTimeCoincideResult = checkTimeCoincide(checkOverTimes, interval, prefix);
            if (StrUtil.isNotBlank(checkTimeCoincideResult)) {
                return RestResult.failed(checkTimeCoincideResult);
            }
            // 时间连续性校验
            Date offsetTime = DateUtil.offsetMinute(startTime, -1);
            if (i > 0 && DateUtil.compare(lastEndTime, offsetTime) != 0) {
                return RestResult.failed(StrUtil.format("【{}】规则标题【{}】的【时段{}】与规则标题【{}】的【时段{}】连续性缺失",
                        prefix, interval.getTitle(), interval.getIndex() + 1, lastTitle, lastIndex + 1));
            }
            // 更新上一个结束时间
            lastStartTime = startTime;
            lastEndTime = endTime;
            lastTitle = interval.getTitle();
            checkOverTimes.add(interval);
        }

        // 检查是否覆盖到 23:59
        return RestResult.success();
    }


    private String checkTimeCoincide(List<TimeIntervalDTO> checkOverTimes, TimeIntervalDTO interval, String prefix) {
        Date checkIntervalStartTime = DateUtil.parseDateTime(StrUtil.format("{} {}:00", "1970-01-01", interval.getStartTime().format(DateTimeFormatter.ofPattern("HH:mm"))));
        Date checkIntervalEnd = DateUtil.parseDateTime(StrUtil.format("{} {}:00", "1970-01-01", interval.getEndTime().format(DateTimeFormatter.ofPattern("HH:mm"))));
        for (TimeIntervalDTO checkOverTime : checkOverTimes) {
            Date checkOverStartTime = DateUtil.parseDateTime(StrUtil.format("{} {}:00", "1970-01-01", checkOverTime.getStartTime().format(DateTimeFormatter.ofPattern("HH:mm"))));
            Date checkOverEndTime = DateUtil.parseDateTime(StrUtil.format("{} {}:00", "1970-01-01", checkOverTime.getEndTime().format(DateTimeFormatter.ofPattern("HH:mm"))));
            if (DateUtil.isIn(checkIntervalStartTime, checkOverStartTime, checkOverEndTime)) {
                return StrUtil.format("【{}】规则标题【{}】的【时段{}】与规则标题【{}】的【时段{}】存在重合", prefix,
                        interval.getTitle(), interval.getIndex() + 1, checkOverTime.getTitle(), checkOverTime.getIndex() + 1);
            } else if (DateUtil.isIn(checkIntervalEnd, checkOverStartTime, checkOverEndTime)) {
                return StrUtil.format("【{}】规则标题【{}】的【时段{}】与规则标题【{}】的【时段{}】存在重合", prefix,
                        interval.getTitle(), interval.getIndex() + 1, checkOverTime.getTitle(), checkOverTime.getIndex() + 1);
            }
        }
        return "";
    }


    /**
     * 模拟计价
     *
     * @param mockPricing
     * @return
     */
    @PostMapping("/mock-pricing")
    public RestResult mockPricing(@RequestBody OnlineValuationMockPricingWrapper mockPricing) {
        return onlineValuationRuleService.mockPricing(mockPricing);
    }


    @PostMapping("/copyRule")
    public RestResult copyRule(@RequestBody Map<String, Object> copyParams) {
        Long ruleId = MapUtil.getLong(copyParams, "id");
        Long driverRegionId = MapUtil.getLong(copyParams, "driverRegionId");
        if (ObjectUtil.isNull(ruleId) || ObjectUtil.isNull(driverRegionId)) {
            return RestResult.failed("缺少必要参数");
        }
        return onlineValuationRuleService.copyRule(ruleId, driverRegionId);
    }
}
